/*
 * This file is part of aion-unique <aion-unique.org>.
 *
 *  aion-unique is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  aion-unique is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package system.handlers.quest.theobomos;

import java.util.Collections;

import com.aionemu.gameserver.model.gameobjects.Item;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.templates.quest.QuestItems;
import com.aionemu.gameserver.network.aion.serverpackets.SM_DIALOG_WINDOW;
import com.aionemu.gameserver.questEngine.QuestEngine;
import com.aionemu.gameserver.questEngine.handlers.QuestHandler;
import com.aionemu.gameserver.questEngine.model.QuestEnv;
import com.aionemu.gameserver.questEngine.model.QuestState;
import com.aionemu.gameserver.questEngine.model.QuestStatus;
import com.aionemu.gameserver.utils.PacketSendUtility;

/**
 * @author Lyahim, Manu72
 * 
 */
public class _3093RecetteSecretedeQuenelles extends QuestHandler
{
	public static void main(String[] args)
	{
		QuestEngine.getInstance().addQuestHandler(new _3093RecetteSecretedeQuenelles());
	}

	private final static int	questId	= 3093;

	public _3093RecetteSecretedeQuenelles()
	{
		super(questId);
		qe.setNpcQuestData(798185).addOnQuestStart(questId); // Bororinerk
		qe.setNpcQuestData(798185).addOnTalkEvent(questId); // Bororinerk
		qe.setNpcQuestData(798177).addOnTalkEvent(questId); // Gastak
		qe.setNpcQuestData(798179).addOnTalkEvent(questId); // Jabala
		qe.setNpcQuestData(203784).addOnTalkEvent(questId); // Hestia
	}

	@Override
	public boolean onDialogEvent(QuestEnv env)
	{
		final Player player = env.getPlayer();
		int targetId = env.getVisibleObject().getNpcId();

		final QuestState qs = player.getQuestStateList().getQuestState(questId);
		if (qs == null || qs.getStatus() == QuestStatus.NONE)
		{
			if (targetId == 798185) // Bororinerk
			{
				if (env.getDialogId() == 25)
					return sendQuestDialog(env, 1011);
				else if (env.getDialogId() == 1002)
				{
					qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
					updateQuestStatus(player, qs);
					PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
					if (Item.addItems(player, Collections.singletonList(new QuestItems(182206062, 1))))
						;
					return true;
				}

				else
					return defaultQuestStartDialog(env);
			}
		}
		else if (qs != null && qs.getStatus() == QuestStatus.REWARD) // Reward
		{
			if (env.getDialogId() == 25)
				return sendQuestDialog(env, 2375);
			else if (env.getDialogId() == 1009)
			{
				qs.setQuestVar(4);
				qs.setStatus(QuestStatus.REWARD);
				updateQuestStatus(player, qs);
				return defaultQuestEndDialog(env);
			}
			else
				return defaultQuestEndDialog(env);
		}

		else if (targetId == 798177) // Gastak
		{

			if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 1)
			{
				if (env.getDialogId() == 25)
					return sendQuestDialog(env, 1352);
				else if (env.getDialogId() == 10000)
				{
					qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
					updateQuestStatus(player, qs);
					PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
					return true;
				}
				else
					return defaultQuestStartDialog(env);
			}

		}

		else if (targetId == 798179) // Jabala
		{
			if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 2)
			{
				if (env.getDialogId() == 25)
					return sendQuestDialog(env, 1693);
				else if (env.getDialogId() == 10001)
				{
					qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
					updateQuestStatus(player, qs);
					PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
					return true;
				}
				else
					return defaultQuestStartDialog(env);
			}
		}

		else if (targetId == 203784) // Hestia
		{
			if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 3)
			{
				if (env.getDialogId() == 25)
					return sendQuestDialog(env, 2034);
				else if (env.getDialogId() == 10002)
				{
					if (Item.addItems(player, Collections.singletonList(new QuestItems(182208052, 1))))
						;
					qs.setStatus(QuestStatus.REWARD);
					updateQuestStatus(player, qs);
					PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
					return true;
				}
				else
					return defaultQuestStartDialog(env);
			}
		}

		return false;
	}
}
